#ifndef __KYLIN_UKEY_H_
#define __KYLIN_UKEY_H_

#include <stdbool.h>

#include "dict.h"

#define LEGACY_SERIAL_LEN 6
#define BATCH_SERIAL_LEN 7
#define NEW_SERIAL_LEN 8


enum
{
	SERIAL_MODE_UNKNOWN = 0,
	SERIAL_MODE_LEGACY,
	SERIAL_MODE_BATCH,
	SERIAL_MODE_NEW
} serial_number_mode;

/*
 * _serial_number_mode, get serial number mode
 */
int _serial_number_mode(const char* serial);

/*
 * _product_type_check, check if product type matches
 */
bool _product_type_check(const char* license_serial, const char* ukey_serial);

/*
 * activate_number_validate_ukey, validate ukey activation code
 * return 1 if valid, or 0 if not
 */
int activate_number_validate_ukey(const char* register_code, const char* ukey_serial, const char* activate_code);

/*
 * activation_expire_date_ukey, get expire date in form of struct tm from ukey activation code
 * return valid expire date pointer if succeed, or NULL if not
 */
struct tm* activation_expire_date_ukey(const char* register_code, const char* ukey_serial, const char* activate_code);

/*
 * ukey_activate_system, activate system with ukey
 * return NO_ERROR if succeed, or error number if not
 */
int ukey_activate_system(const char* license_serial, 
			 const char* kyinfo_ukey, const char* expire_date);

/*
 * _kylin_activation_activate_system, activate system
 * return NO_ERROR if succeed, or error number if not
 */
int _kylin_activation_activate_system(const char* activation_code, const char* ukey_hid, const char* serial_no, int prompt);

/*
 * _kylin_activation_activate_system_test, test if activation can succeed
 * return NO_ERROR if succeed, or error number if not
 */
int _kylin_activation_activate_system_test(const char* activation_code_with_hyphen, const char* ukey_hid, const char* serial_no);

/*
 * ukey_get_hid, get hid string of ukey
 * return hid string if succeed, or NULL if not
 */
char* ukey_get_hid();

/*
 * ukey_dump, dump ukey information to file f
 * encrypt: whether encryption is needed or not
 * display_all: whether display all information or not
 * return NO_ERROR if succeed, or error number if not
 */
int ukey_dump(FILE* f, int encrypt, int display_all);

/*
 * find ukey
 * return NO_ERROR if vikey is inserted, or error number if not
 */
int ukey_find();

/*
 * find ukey by usb bus
 * return NO_ERROR if vikey is inserted, or error number if not
 */
int ukey_usb_bus_find(int*);

/*
 * load ukey device
 * return NO_ERROR if vikey is inserted, or error number if not
 */
int ukey_device_load(int);

#endif
